package com.art.sunflower.service.impl;

import com.art.sunflower.exception.NullNewsException;
import com.art.sunflower.exception.NullWorkException;
import com.art.sunflower.mapper.SchoolTeacherMapper;
import com.art.sunflower.pojo.SchoolTeacher;
import com.art.sunflower.service.SchoolTeacherService;
import com.art.sunflower.util.MyPageInfo;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
@Transactional
public class SchoolTeacherServiceImpl implements SchoolTeacherService {
    @Resource
    SchoolTeacherMapper schoolTeacherMapper;

    public int insert(SchoolTeacher schoolTeacher) {
        return schoolTeacherMapper.insert(schoolTeacher);
    }

    @Override
    public int update(SchoolTeacher schoolTeacher) {
        return schoolTeacherMapper.update(schoolTeacher);
    }

    @Override
    public int updateIndex(int id, boolean isIndex) {
        return schoolTeacherMapper.updateIndex(id, isIndex);
    }

    @Override
    public int delete(int id) {
        return schoolTeacherMapper.delete(id);
    }

    @Override
    public MyPageInfo listAll(Integer pageSize, Integer pageNo) throws NullWorkException {
        //需要进行分页
        PageHelper.startPage(pageNo, pageSize);
        List<Map<String, Object>> work = schoolTeacherMapper.listAll();
        if (work.size() == 0)
            throw new NullNewsException();
        PageInfo<Map<String, Object>> pageInfo = new PageInfo<>(work);
        return new MyPageInfo(pageInfo);
    }

    @Override
    public SchoolTeacher selectOne(int id) {
        return schoolTeacherMapper.selectOne(id);
    }
}
